<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: freeamount.php 276 2013-09-23 08:54:19Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 276 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-23 08:54:19 +0000 (Mon, 23 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

class freeamount {
    var $code, $title, $description, $icon, $enabled, $db;

    function __construct() {
    	global $db;

		$this->code = 'freeamount';
		$this->title = MODULE_SHIPPING_FREEAMOUNT_TEXT_TITLE;
		$this->description = MODULE_SHIPPING_FREEAMOUNT_TEXT_DESCRIPTION;
		$this->icon = '';
		$this->sort_order = MODULE_SHIPPING_FREEAMOUNT_SORT_ORDER;
		$this->enabled = ((MODULE_SHIPPING_FREEAMOUNT_STATUS == 'True') ? true : false);
		$this->db = $db;
    }

    function quote($method = '') {
    	global $price;
      $freeShippingAmount = $price->_ext->getFreeShippingAmount();

    	if ( MODULE_SHIPPING_FREEAMOUNT_DISPLAY == 'False' || $freeShippingAmount == -1)
  			return;
      
  		$this->quotes = array('id' => $this->code,
								'module' => MODULE_SHIPPING_FREEAMOUNT_TEXT_TITLE);

		if(!$price->_ext->isFreeShipping())
			$this->quotes['error'] = sprintf(MODULE_SHIPPING_FREEAMOUNT_TEXT_WAY,$price->format($freeShippingAmount,true,0,true));
		else {
			$this->quotes['methods'] = array(array('id'    => $this->code,
													'title' => sprintf(MODULE_SHIPPING_FREEAMOUNT_TEXT_WAY,$price->format($freeShippingAmount,true,0,true)),
													'cost'  => 0));
		}
		if(not_null($this->icon))
			$this->quotes['icon'] = image($this->icon, $this->title);

		return $this->quotes;
    }

	function check() {
		if (!isset($this->_check)) {
			$check = $this->db->db_query("SELECT configuration_value FROM ".TABLE_CONFIGURATION." WHERE configuration_key = 'MODULE_SHIPPING_FREEAMOUNT_STATUS'");
			$this->_check = $check->_numOfRows;
		}
		return $this->_check;
	}

    function install() {
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_FREEAMOUNT_STATUS', 'True', '6', '7', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_FREEAMOUNT_ALLOWED', '', '6', '0', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('MODULE_SHIPPING_FREEAMOUNT_DISPLAY', 'True', '6', '7', 'cfg_select_option(array(\'True\', \'False\'), ', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_FREEAMOUNT_AMOUNT', '50.00', '6', '8', now())");
		$this->db->db_query("INSERT INTO ".TABLE_CONFIGURATION." (configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('MODULE_SHIPPING_FREEAMOUNT_SORT_ORDER', '0', '6', '4', now())");
    }

    function remove() {
		$this->db->db_query("DELETE FROM ".TABLE_CONFIGURATION." WHERE configuration_key IN ('".implode("', '", $this->keys())."')");
    }

    function keys() {
		return array('MODULE_SHIPPING_FREEAMOUNT_STATUS','MODULE_SHIPPING_FREEAMOUNT_ALLOWED', 'MODULE_SHIPPING_FREEAMOUNT_DISPLAY', 'MODULE_SHIPPING_FREEAMOUNT_AMOUNT','MODULE_SHIPPING_FREEAMOUNT_SORT_ORDER');
    }
}
?>